<?php include dirname(__FILE__) . '/header.html'; ?>

<? if ($vars['quality']->revision): ?>
    <p>Revision <a href="#"><?php echo $vars['quality']->revision?></a>, commited by <?php echo $vars['quality']->author?><br/>
        <?php echo $vars['quality']->log?></p>
<? endif; ?>
    
<p><?php echo $vars['quality']->lines?> lines,
    <?php echo $vars['quality']->errors?> errors,
    <?php echo $vars['quality']->warnings?> warnings
    </p>
    
<? 
$errors = array();
foreach ($vars['info']->children() as $err) {
    $lineNo = (string)$err['line'];
    $type = (string)$err->getName();
    
    if (!isset($errors[$lineNo])) {
        $errors[$lineNo] = array();
        $errors[$lineNo]['cnt'] = 1;
    } else
        $errors[$lineNo]['cnt']++; 
    
    if (!isset($errors[$lineNo][$type]))
        $errors[$lineNo][$type] = array();
        
    $errors[$lineNo][$type][] = (string)$err; 
}
?>

    <table class="code">
        <thead><tr>
            <th width="60px" title="Line numbers" class="right">Line</th>
            <th></th>
        </tr></thead>
        <tbody>

    <? foreach (file($vars['source']) as $id=>$line): ?>
        <? $lineNo = $id+1 ?>
        <tr><th
            <?php echo (isset($errors[$lineNo]) ? " rowspan='2' class='errors'" : false)?>
            ><?php echo $lineNo?></th><td
            <?php echo (isset($errors[$lineNo]) ? " class='errors'" : false)?>
            ><?php echo htmlspecialchars($line)?></td></tr>
     
        <? if (isset($errors[$lineNo])): ?>
            <tr><td class="comment">
            <? foreach (array('error', 'warning') as $type): ?>
                <? if (isset($errors[$lineNo][$type])): ?>
                    <? foreach ($errors[$lineNo][$type] as $err): ?>
                        <span class="<?php echo $type?>"><?php echo htmlspecialchars($err)?></span><br/>
                    <? endforeach; ?>
                <? endif; ?>
            <? endforeach; ?>
            </td></tr>
        <? endif; ?>

    <? endforeach; ?>

    </tbody>
</table>

<?php include dirname(__FILE__) . '/footer.html'; ?>
